home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / GCC / CC1.ZIP / !gcc / files / c / dhry_1 < prev    next >
Text File  |  1995-04-05  |  12KB  |  398 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *                   "DHRYSTONE" Benchmark Program
  5.  *                   -----------------------------
  6.  *
  7.  *  Version:    C, Version 2.1
  8.  *
  9.  *  File:       dhry_1.c (part 2 of 3)
  10.  *
  11.  *  Date:       May 25, 1988
  12.  *
  13.  *  Author:     Reinhold P. Weicker
  14.  *
  15.  ****************************************************************************
  16.  */
  17.  
  18. #include "dhry.h"
  19.  
  20. /* Global Variables: */
  21.  
  22. Rec_Pointer     Ptr_Glob,
  23.                 Next_Ptr_Glob;
  24. int             Int_Glob;
  25. Boolean         Bool_Glob;
  26. char            Ch_1_Glob,
  27.                 Ch_2_Glob;
  28. int             Arr_1_Glob [50];
  29. int             Arr_2_Glob [50] [50];
  30.  
  31. int _exit_dummy_decl;
  32.  
  33. extern char     *malloc ();
  34. Enumeration     Func_1 ();
  35.   /* forward declaration necessary since Enumeration may not simply be int */
  36.  
  37. #ifndef REG
  38.         Boolean Reg = false;
  39. #define REG
  40.         /* REG becomes defined as empty */
  41.         /* i.e. no register variables   */
  42. #else
  43.         Boolean Reg = true;
  44. #endif
  45.  
  46. /* variables for time measurement: */
  47.  
  48. #ifdef TIMES
  49. struct tms      time_info;
  50. extern  int     times ();
  51.                 /* see library function "times" */
  52. #define Too_Small_Time (2*HZ)
  53.                 /* Measurements should last at least about 2 seconds */
  54. #endif
  55. #ifdef TIME
  56. extern long     time();
  57.                 /* see library function "time"  */
  58. #define Too_Small_Time 2
  59.                 /* Measurements should last at least 2 seconds */
  60. #endif
  61. #ifdef MSC_CLOCK
  62. extern clock_t clock();
  63. #define Too_Small_Time (2*HZ)
  64. #endif
  65.  
  66. long            Begin_Time,
  67.                 End_Time,
  68.                 User_Time;
  69. float           Microseconds,
  70.                 Dhrystones_Per_Second;
  71.  
  72. /* end of variables for time measurement */
  73.  
  74.  
  75. main ()
  76. /*****/
  77.  
  78.   /* main program, corresponds to procedures        */
  79.   /* Main and Proc_0 in the Ada version             */
  80. {
  81.         One_Fifty       Int_1_Loc;
  82.   REG   One_Fifty       Int_2_Loc;
  83.         One_Fifty       Int_3_Loc;
  84.   REG   char            Ch_Index;
  85.         Enumeration     Enum_Loc;
  86.         Str_30          Str_1_Loc;
  87.         Str_30          Str_2_Loc;
  88.   REG   int             Run_Index;
  89.   REG   int             Number_Of_Runs;
  90.  
  91.   /* Initializations */
  92.  
  93.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  94.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  95.  
  96.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  97.   Ptr_Glob->Discr                       = Ident_1;
  98.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  99.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  100.   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  101.           "DHRYSTONE PROGRAM, SOME STRING");
  102.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  103.  
  104.   Arr_2_Glob [8][7] = 10;
  105.         /* Was missing in published program. Without this statement,    */
  106.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  107.         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  108.         /* overflow may occur for this array element.                   */
  109.  
  110.   printf ("\n");
  111.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  112.   printf ("\n");
  113.   if (Reg)
  114.   {
  115.     printf ("Program compiled with 'register' attribute\n");
  116.     printf ("\n");
  117.   }
  118.   else
  119.   {
  120.     printf ("Program compiled without 'register' attribute\n");
  121.     printf ("\n");
  122.   }
  123.   printf ("Please give the number of runs through the benchmark: ");
  124.   {
  125.     int n;
  126.     scanf ("%d", &n);
  127.     Number_Of_Runs = n;
  128.   }
  129.   printf ("\n");
  130.  
  131.   printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  132.  
  133.   /***************/
  134.   /* Start timer */
  135.   /***************/
  136.  
  137. #ifdef TIMES
  138.   times (&time_info);
  139.   Begin_Time = (long) time_info.tms_utime;
  140. #endif
  141. #ifdef TIME
  142.   Begin_Time = time ( (long *) 0);
  143. #endif
  144. #ifdef MSC_CLOCK
  145.   Begin_Time = clock();
  146. #endif
  147.  
  148.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  149.   {
  150.  
  151.     Proc_5();
  152.     Proc_4();
  153.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  154.     Int_1_Loc = 2;
  155.     Int_2_Loc = 3;
  156.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  157.     Enum_Loc = Ident_2;
  158.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  159.       /* Bool_Glob == 1 */
  160.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  161.     {
  162.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  163.         /* Int_3_Loc == 7 */
  164.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  165.         /* Int_3_Loc == 7 */
  166.       Int_1_Loc += 1;
  167.     } /* while */
  168.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  169.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  170.       /* Int_Glob == 5 */
  171.     Proc_1 (Ptr_Glob);
  172.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  173.                              /* loop body executed twice */
  174.     {
  175.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  176.           /* then, not executed */
  177.         {
  178.         Proc_6 (Ident_1, &Enum_Loc);
  179.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  180.         Int_2_Loc = Run_Index;
  181.         Int_Glob = Run_Index;
  182.         }
  183.     }
  184.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  185.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  186.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  187.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  188.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  189.     Proc_2 (&Int_1_Loc);
  190.       /* Int_1_Loc == 5 */
  191.  
  192.   } /* loop "for Run_Index" */
  193.  
  194.   /**************/
  195.   /* Stop timer */
  196.   /**************/
  197.  
  198. #ifdef TIMES
  199.   times (&time_info);
  200.   End_Time = (long) time_info.tms_utime;
  201. #endif
  202. #ifdef TIME
  203.   End_Time = time ( (long *) 0);
  204. #endif
  205. #ifdef MSC_CLOCK
  206.   End_Time = clock();
  207. #endif
  208.  
  209.   printf ("Execution ends\n");
  210.   printf ("\n");
  211.   printf ("Final values of the variables used in the benchmark:\n");
  212.   printf ("\n");
  213.   printf ("Int_Glob:            %d\n", Int_Glob);
  214.   printf ("        should be:   %d\n", 5);
  215.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  216.   printf ("        should be:   %d\n", 1);
  217.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  218.   printf ("        should be:   %c\n", 'A');
  219.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  220.   printf ("        should be:   %c\n", 'B');
  221.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  222.   printf ("        should be:   %d\n", 7);
  223.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  224.   printf ("        should be:   Number_Of_Runs + 10\n");
  225.   printf ("Ptr_Glob->\n");
  226.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  227.   printf ("        should be:   (implementation-dependent)\n");
  228.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  229.   printf ("        should be:   %d\n", 0);
  230.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  231.   printf ("        should be:   %d\n", 2);
  232.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  233.   printf ("        should be:   %d\n", 17);
  234.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  235.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  236.   printf ("Next_Ptr_Glob->\n");
  237.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  238.   printf ("        should be:   (implementation-dependent), same as above\n");
  239.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  240.   printf ("        should be:   %d\n", 0);
  241.   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  242.   printf ("        should be:   %d\n", 1);
  243.   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  244.   printf ("        should be:   %d\n", 18);
  245.   printf ("  Str_Comp:          %s\n",
  246.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  247.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  248.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  249.   printf ("        should be:   %d\n", 5);
  250.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  251.   printf ("        should be:   %d\n", 13);
  252.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  253.   printf ("        should be:   %d\n", 7);
  254.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  255.   printf ("        should be:   %d\n", 1);
  256.   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
  257.   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
  258.   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
  259.   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
  260.   printf ("\n");
  261.  
  262.   User_Time = End_Time - Begin_Time;
  263.  
  264.   if (User_Time < Too_Small_Time)
  265.   {
  266.     printf ("Measured time too small to obtain meaningful results\n");
  267.     printf ("Please increase number of runs\n");
  268.     printf ("\n");
  269.   }
  270.   else
  271.   {
  272. #ifdef TIME
  273.     Microseconds = (float) User_Time * Mic_secs_Per_Second
  274.                         / (float) Number_Of_Runs;
  275.     Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  276. #else
  277.     Microseconds = (float) User_Time * Mic_secs_Per_Second
  278.                         / ((float) HZ * ((float) Number_Of_Runs));
  279.     Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
  280.                         / (float) User_Time;
  281. #endif
  282.     printf ("Microseconds for one run through Dhrystone: ");
  283.     printf ("%6.1f \n", Microseconds);
  284.     printf ("Dhrystones per Second:                      ");
  285.     printf ("%6.1f \n", Dhrystones_Per_Second);
  286.     printf ("\n");
  287.   }
  288.  
  289. }
  290.  
  291.  
  292. Proc_1 (Ptr_Val_Par)
  293. /******************/
  294.  
  295. REG Rec_Pointer Ptr_Val_Par;
  296.     /* executed once */
  297. {
  298.   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
  299.                                         /* == Ptr_Glob_Next */
  300.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  301.   /* corresponds to "rename" in Ada, "with" in Pascal           */
  302.  
  303.   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  304.   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  305.   Next_Record->variant.var_1.Int_Comp
  306.         = Ptr_Val_Par->variant.var_1.Int_Comp;
  307.   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  308.   Proc_3 (&Next_Record->Ptr_Comp);
  309.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  310.                         == Ptr_Glob->Ptr_Comp */
  311.   if (Next_Record->Discr == Ident_1)
  312.     /* then, executed */
  313.   {
  314.     Next_Record->variant.var_1.Int_Comp = 6;
  315.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  316.            &Next_Record->variant.var_1.Enum_Comp);
  317.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  318.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  319.            &Next_Record->variant.var_1.Int_Comp);
  320.   }
  321.   else /* not executed */
  322.     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  323. } /* Proc_1 */
  324.  
  325.  
  326. Proc_2 (Int_Par_Ref)
  327. /******************/
  328.     /* executed once */
  329.     /* *Int_Par_Ref == 1, becomes 4 */
  330.  
  331. One_Fifty   *Int_Par_Ref;
  332. {
  333.   One_Fifty  Int_Loc;
  334.   Enumeration   Enum_Loc;
  335.  
  336.   Int_Loc = *Int_Par_Ref + 10;
  337.   do /* executed once */
  338.     if (Ch_1_Glob == 'A')
  339.       /* then, executed */
  340.     {
  341.       Int_Loc -= 1;
  342.       *Int_Par_Ref = Int_Loc - Int_Glob;
  343.       Enum_Loc = Ident_1;
  344.     } /* if */
  345.   while (Enum_Loc != Ident_1); /* true */
  346. } /* Proc_2 */
  347.  
  348.  
  349. Proc_3 (Ptr_Ref_Par)
  350. /******************/
  351.     /* executed once */
  352.     /* Ptr_Ref_Par becomes Ptr_Glob */
  353.  
  354. Rec_Pointer *Ptr_Ref_Par;
  355.  
  356. {
  357.   if (Ptr_Glob != Null)
  358.     /* then, executed */
  359.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  360.   Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  361. } /* Proc_3 */
  362.  
  363.  
  364. Proc_4 () /* without parameters */
  365. /*******/
  366.     /* executed once */
  367. {
  368.   Boolean Bool_Loc;
  369.  
  370.   Bool_Loc = Ch_1_Glob == 'A';
  371.   Bool_Glob = Bool_Loc | Bool_Glob;
  372.   Ch_2_Glob = 'B';
  373. } /* Proc_4 */
  374.  
  375.  
  376. Proc_5 () /* without parameters */
  377. /*******/
  378.     /* executed once */
  379. {
  380.   Ch_1_Glob = 'A';
  381.   Bool_Glob = false;
  382. } /* Proc_5 */
  383.  
  384.  
  385.         /* Procedure for the assignment of structures,          */
  386.         /* if the C compiler doesn't support this feature       */
  387. #ifdef  NOSTRUCTASSIGN
  388. memcpy (d, s, l)
  389. register char   *d;
  390. register char   *s;
  391. register int    l;
  392. {
  393.         while (l--) *d++ = *s++;
  394. }
  395. #endif
  396.  
  397.  
  398.